package com.example.lockfulldemo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.lockfulldemo.bo.TicketQuery;
import com.example.lockfulldemo.bo.TicketRes;
import com.example.lockfulldemo.entity.TicketEntity;
import com.example.lockfulldemo.service.DemoService;
import com.example.lockfulldemo.tools.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author admin
 */
@Slf4j
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Resource
    private DemoService demoService;

    @PostMapping("/upload")
    public String uploadFile(MultipartFile multipartFile) {
        System.out.println(multipartFile);
        return null;
    }

    @GetMapping("/query/cause")
    public String queryRefundCause() {
        ThreadLocalUtil.set(TicketEntity.builder().time(Thread.currentThread().getName()).build());
        demoService.demo();
        System.out.println(123);
//        String jsonStr = JSONUtil.toJsonStr(WechatMessageBo.builder()
//                .msgtype("text")
//                .text(WechatMessageBo.WechatMessageText.builder()
//                        .content("测试")
//                        .mentioned_mobile_list("13819126424")
//                        .build())
//                .build());
//        WechatMessageBo build = WechatMessageBo.builder()
//                .msgtype("text")
//                .text(WechatMessageBo.WechatMessageText.builder()
//                        .content("测试")
//                        .mentioned_mobile_list(jsonStr)
//                        .build())
//                .build();
//        return JSONUtil.toJsonStr(build);

        return "no auth！";

//        return JSONUtil.toJsonStr(WechatMessageBo.builder()
//                .msgtype("text")
//                .text(WechatMessageBo.WechatMessageText.builder()
//                        .content("测试")
//                        .mentioned_mobile_list("13819126424")
//                        .build())
//                .build());
    }

    @GetMapping("/query/date")
    public TicketRes queryDate(@RequestBody TicketQuery ticketQuery) {
        TicketRes res = new TicketRes();
        BeanUtil.copyProperties(ticketQuery, res);
//        throw new BizException(ErrorCodeEnum.AUTH_ERROR);
        return res;
    }

    @GetMapping("/query/aaa")
    public String queryAaa() {
        return "success";
    }

    @PostMapping("/post")
    public TicketRes postData(@RequestBody TicketQuery ticketQuery) {
        TicketRes res = new TicketRes();
        BeanUtil.copyProperties(ticketQuery, res);
        System.out.println(111);
        return res;
    }

    @GetMapping("/query/date1")
    public void queryDate(@RequestParam(required = true) Long id) {
        System.out.println(1);
    }
//    @GetMapping("/valid/test")
//    public void validTest(@RequestBody ValidTest validTest) {
//        SpringValidatorAdapter validatorAdapter = new SpringValidatorAdapter(messageValidator);
//        BeanPropertyBindingResult result = new BeanPropertyBindingResult(message, messageClass.getName());
//        validatorAdapter.validate(message, result);
//    }


}
